<?php

namespace App\Http\Controllers\OpenShop\Organization;

use App\Http\Controllers\BaseController;
use App\Http\Validate\OpenShop\Organization\WarZoneValidate;
use App\Service\OpenShop\Organization\WarZoneService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class WarZoneController extends BaseController
{
    /**
     * 列表
     *
     * @return JsonResponse
     */
    public function index(): JsonResponse
    {
        return $this->success(WarZoneService::index());
    }

    /**
     * 详情
     *
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function detail(Request $request, int $id): JsonResponse
    {
        WarZoneValidate::detailValidate($request->merge(["id" => $id])->all());
        return $this->success(WarZoneService::detail($id));
    }

    /**
     * 更新
     *
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function update(Request $request, int $id): JsonResponse
    {
        WarZoneService::update(
            $request->user()->id,
            WarZoneValidate::updateValidate($request->merge(["id" => $id])->all())
        );
        return $this->success();
    }

}
